using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace Toenda.Foundation.Utility {
	/// <summary>
	/// Class Validator
	/// </summary>
	public class Validator {
		/// <summary>
		/// Checks if a number is a odd number
		/// </summary>
		/// <param name="number"></param>
		/// <returns></returns>
		public static bool IsOddNumbered(int number) {
			return ((number & 1) == 1);
		}

		/// <summary>
		/// Checks if a number is a odd number
		/// </summary>
		/// <param name="number"></param>
		/// <returns></returns>
		public static bool IsOddNumbered(long number) {
			return ((number & 1) == 1);
		}

		/// <summary>
		/// Checks if a number is a odd number
		/// </summary>
		/// <param name="number"></param>
		/// <returns></returns>
		public static bool IsOddNumbered(short number) {
			return ((number & 1) == 1);
		}

		/// <summary>
		/// Check if a double number has number after his point
		/// </summary>
		/// <param name="number"></param>
		/// <returns></returns>
		public static bool IsNaturalNumber(double number) {
			int res = 0;

			if(int.TryParse(number.ToString(), out res)) {
				return true;
			}
			else {
				return false;
			}
		}

		/// <summary>
		/// Check if a number is a negative number
		/// </summary>
		/// <param name="value"></param>
		/// <returns></returns>
		public static bool IsNegativeNumber(short value) {
			return ( value > -1 ? false : true );
		}

		/// <summary>
		/// Check if a number is a negative number
		/// </summary>
		/// <param name="value"></param>
		/// <returns></returns>
		public static bool IsNegativeNumber(int value) {
			return ( value > -1 ? false : true );
		}

		/// <summary>
		/// Check if a number is a negative number
		/// </summary>
		/// <param name="value"></param>
		/// <returns></returns>
		public static bool IsNegativeNumber(long value) {
			return ( value > -1 ? false : true );
		}

		/// <summary>
		/// Check if a number is a negative number
		/// </summary>
		/// <param name="value"></param>
		/// <returns></returns>
		public static bool IsNegativeNumber(double value) {
			return ( value > -1 ? false : true );
		}

		/// <summary>
		/// Check if a number is a negative number
		/// </summary>
		/// <param name="value"></param>
		/// <returns></returns>
		public static bool IsNegativeNumber(float value) {
			return ( value > -1 ? false : true );
		}

		/// <summary>
		/// Check if a number is a negative number
		/// </summary>
		/// <param name="value"></param>
		/// <returns></returns>
		public static bool IsNegativeNumber(decimal value) {
			return ( value > -1 ? false : true );
		}

		/// <summary>
		/// Check if a char symbol is in a char array
		/// </summary>
		/// <param name="list">The char array.</param>
		/// <param name="symbol">The char symbol.</param>
		/// <returns></returns>
		public static bool IsInList(char[] list, char symbol) {
			foreach(char c in list) {
				if(c == symbol) {
					return true;
				}
			}

			return false;
		}

		/// <summary>
		/// Determines whether [is in list] [the specified list].
		/// </summary>
		/// <typeparam name="T"></typeparam>
		/// <param name="list">The list.</param>
		/// <param name="item">The item.</param>
		/// <returns>
		/// 	<c>true</c> if [is in list] [the specified list]; otherwise, <c>false</c>.
		/// </returns>
		public static bool IsInList<T>(List<T> list, T item) {
			return list.Exists(delegate(T single) { return single.Equals(item); });
		}

		/// <summary>
		/// Check if a variable is set
		/// </summary>
		/// <typeparam name="T"></typeparam>
		/// <param name="variable"></param>
		/// <returns></returns>
		public static bool IsSet<T>(T variable) {
			if(variable != null) {
				return true;
			}
			else {
				return false;
			}
		}
	}
}
